# 通过推理时传入的参数得到确切的每个text的位置
dir=/home/node54_tmpdata/yzli/wenet_whisper_finetune/examples/wenetspeech/whisper/exp/qwen2_multi_task_6gpus_gxl_adapter_init_asr-sot_whisper
ckpt_name=epoch_20.pt
test_data_dir='/home/node54_tmpdata/xlgeng/code/wenet_whisper_finetune/examples/wenetspeech/whisper/data/test_sets'


# chat
test_sets='chat'
# 写一个循环，遍历test_sets
for test_set in $test_sets; do
  echo "test_set: $test_set"

  # 拼接路径
  hyp_text_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/text"
  ref_text_path_item="$test_data_dir/${test_set}/text"
  res_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl"

  # 检查文件是否存在
  if [ ! -f "$hyp_text_path_item" ]; then
    echo "text path $hyp_text_path_item does not exist."
    continue
  fi

  # 执行 Python 脚本
  python compute_bleu_for_chat_task.py --hyp_file "$hyp_text_path_item" --ref_file "$ref_text_path_item" --output_file "$res_path_item"
done

# align
test_sets='align/aishell2'
# 写一个循环，遍历test_sets
for test_set in $test_sets; do
  echo "test_set: $test_set"

 # 拼接路径
  hyp_text_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/text"
  ref_text_path_item="$test_data_dir/${test_set}/text"
  res_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_er"
  res_path_item2="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_ter"

  echo "hyp_text_path_item: $hyp_text_path_item"
  echo "ref_text_path_item: $ref_text_path_item"
  echo "res_path_item: $res_path_item"
  echo "res_path_item2: $res_path_item2"

  # 检查文件是否存在
  if [ ! -f "$hyp_text_path_item" ]; then
    echo "text path $hyp_text_path_item does not exist."
    continue
  fi

  # 执行 Python 脚本
  # 计算时间戳的概率
#  python compute_er_for_align.py --hyp_file "$hyp_text_path_item" --ref_file "$ref_text_path_item" --output_file "$res_path_item"
  python compute_ter_for_align.py --char=1 --v=1 \
      $ref_text_path_item $hyp_text_path_item > $res_path_item2
  tail -n 10 $res_path_item2
done


# age
test_sets='age'
# 写一个循环，遍历test_sets
for test_set in $test_sets; do
  echo "test_set: $test_set"

 # 拼接路径
  hyp_text_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/text"
  ref_text_path_item="$test_data_dir/${test_set}/text"
  res_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_er"
  res_path_item2="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_ter"

  echo "hyp_text_path_item: $hyp_text_path_item"
  echo "ref_text_path_item: $ref_text_path_item"
  echo "res_path_item: $res_path_item"
  echo "res_path_item2: $res_path_item2"

  # 检查文件是否存在
  if [ ! -f "$hyp_text_path_item" ]; then
    echo "text path $hyp_text_path_item does not exist."
    continue
  fi

  # 执行 Python 脚本
  # 计算时间戳的概率
  python compute_acc_for_age.py --hyp_file "$hyp_text_path_item" --output_file "$res_path_item"
done


# gender
test_sets='gender'
# 写一个循环，遍历test_sets
for test_set in $test_sets; do
  echo "test_set: $test_set"

 # 拼接路径
  hyp_text_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/text"
  ref_text_path_item="$test_data_dir/${test_set}/text"
  res_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_er"
  res_path_item2="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_ter"

  echo "hyp_text_path_item: $hyp_text_path_item"
  echo "ref_text_path_item: $ref_text_path_item"
  echo "res_path_item: $res_path_item"
  echo "res_path_item2: $res_path_item2"

  # 检查文件是否存在
  if [ ! -f "$hyp_text_path_item" ]; then
    echo "text path $hyp_text_path_item does not exist."
    continue
  fi

  # 执行 Python 脚本
  # 计算时间戳的概率
  python compute_acc_for_gender.py --hyp_file "$hyp_text_path_item" --output_file "$res_path_item"
done

# caption
test_sets='caption'
# 写一个循环，遍历test_sets
for test_set in $test_sets; do
  echo "test_set: $test_set"

 # 拼接路径
  hyp_text_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/text"
  ref_text_path_item="$test_data_dir/${test_set}/text"
  res_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_er"
  res_path_item2="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_ter"

  echo "hyp_text_path_item: $hyp_text_path_item"
  echo "ref_text_path_item: $ref_text_path_item"
  echo "res_path_item: $res_path_item"
  echo "res_path_item2: $res_path_item2"

  # 检查文件是否存在
  if [ ! -f "$hyp_text_path_item" ]; then
    echo "text path $hyp_text_path_item does not exist."
    continue
  fi

  # 执行 Python 脚本
  # 计算时间戳的概率
  python compute_acc_for_caption.py --hyp_file "$hyp_text_path_item" --output_file "$res_path_item"
done

# emotion
test_sets='emotion'
# 写一个循环，遍历test_sets
for test_set in $test_sets; do
  echo "test_set: $test_set"

 # 拼接路径
  hyp_text_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/text"
  ref_text_path_item="$test_data_dir/${test_set}/text"
  res_path_item="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_er"
  res_path_item2="$dir/${test_set}_${ckpt_name}_chunk-1_ctc0_reverse0.0_blankpenalty0.0_lengthpenalty0.0/llmasr_decode/wer_gxl_ter"

  echo "hyp_text_path_item: $hyp_text_path_item"
  echo "ref_text_path_item: $ref_text_path_item"
  echo "res_path_item: $res_path_item"
  echo "res_path_item2: $res_path_item2"

  # 检查文件是否存在
  if [ ! -f "$hyp_text_path_item" ]; then
    echo "text path $hyp_text_path_item does not exist."
    continue
  fi

  # 执行 Python 脚本
  # 计算时间戳的概率
  python compute_acc_for_emotion.py --hyp_file "$hyp_text_path_item" --output_file "$res_path_item"
done